package com.zhangbo.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;
import com.zhangbo.entity.User;
import com.zhangbo.service.ArticleService;
import com.zhangbo.service.UserService;

@Controller
@RequestMapping("admin")
public class AdminController {
	
	@Autowired
	UserService userservice;
	
	@Autowired
	ArticleService articleService;
	
	@RequestMapping("index")
	public String index() {
		return "admin/index";
	}
	
	@RequestMapping("userlist")
	public String userlist(HttpServletRequest request,
			@RequestParam(defaultValue="1") int page) {
		PageInfo<User> list = userservice.list(page);
		request.setAttribute("list", list);
		return "admin/userlist";
	}
	
	@RequestMapping("articlelist")
	public String article(HttpServletRequest request,
			@RequestParam(defaultValue="1") int page) {
		PageInfo pageInfo = articleService.list(page);
		List list = pageInfo.getList();
		list.forEach(ar->{
			
			System.out.println("article is "+ar);
		});
		request.setAttribute("articlePage",pageInfo);
		return "admin/articlelist";
	}
}

